﻿

var method = {
    minWidth: 100,
    minHeight: 100,
    overLayerClass: "shantu_Overlayer",
    thumbImgClass: "ThumbImg",
    thumbImgDivClass: "ThumbImgDiv",
    collectionBtnClass: "CollectionBtn",
    noImgTip: "亲，没有找到合适大小的图片，图片宽高必须大于100像素哦~",
    //获取所有符合大小的图片
    getVerifiedImgs: function () {
        this.getIframeImgs();
        var imgArr = new Array();
        $("img:visible").each(function () {
            var currentImg = $(this);
            if (currentImg.attr("src").indexOf("data:") != 0
                    && currentImg.width() >= method.minWidth
                    && currentImg.height() >= method.minHeight) {
                imgArr.push(currentImg);
            }
        });
        return imgArr;
    }, //获取iframe里的images
    getIframeImgs: function () {
        $("iframe").each(function () { 
            
        });
        alert($($("iframe").eq(0).get(0).contentDocument).find("img").length);
    },
    //悬浮时，显示/隐藏采集按钮
    showCollectionBtn: function (container) {
        container
        .mouseover(function () {
            $(this).find("." + method.collectionBtnClass + "").css("display", "block");
        })
        .mouseout(function () {
            $(this).find("." + method.collectionBtnClass + "").css("display", "none");
        });
    },
    //生成遮罩层
    generateOverlayer: function () {
        var overyLayer = $("<div/>").addClass(this.overLayerClass);
        return overyLayer;
    },
    //生成图片缩略图
    generateThumbImg: function (imgOjb) {
        var thumbImg = $("<img/>").attr("src", imgOjb.attr("src")).addClass(this.thumbImgClass);
        var collectionBtn = $("<strong/>").css("display", "none").addClass(this.collectionBtnClass);
        var containerDiv = $("<div/>").addClass(this.thumbImgDivClass).append(thumbImg).append(collectionBtn);
        this.showCollectionBtn(containerDiv);
        return containerDiv;
    },
    //显示图片采集板块
    showImgs: function () {
        var imgs = this.getVerifiedImgs();
        if (imgs.length <= 0)
        { alert(this.noImgTip); return; }
        var overlayer = this.generateOverlayer();
        $(imgs).each(function () {
            overlayer.append(method.generateThumbImg($(this)));
        });
        var css = $("<link/>").attr("rel", "stylesheet").attr("type", "text/css").attr("href", "http://www.a.com:4500/Content/shantu.css");
        $("head").eq(0).append(css);
        $("body").append(overlayer);
    },
    test: function () {
        alert('bbbaaa');
    }
};
method.showImgs();




